|
|
|
|
|
|
|
This code looks similar to the code used to monitor the add record events. The only thing different here is that you force the ReBind method to refresh the data grid after the canceled attempt to update the record. |
|
|
|
|
|
|
|
|
Now add the code to confirm the update of the record. Add the following code to the DBGrid1.AfterUpdate event: |
|
|
|
|
|
|
|
|
Private Sub DBGrid1_AfterUpdate()
'
' tell 'em!
'
MsgBox "The record has been updated.", vbInformation, "DBGrid.AfterUpdate"
End Sub |
|
|
|
|
|
|
|
|
Now save and run the project. When you press a key in any column of an existing record, you'll see a message asking you to confirm the update. When you move off the record, you'll see a message telling you the record has been updated. |
|
|
|
|
|
|
|
|
Now add some events to track any attempts to delete existing records. Place the code in Listing 12.3 in the DBGrid1.BeforeDelete event. |
|
|
|
|
|
|
|
|
Listing 12.3. Code to track for record deletes. |
|
|
|
|
|
|
|
|
Private Sub DBGrid1_BeforeDelete(Cancel As Integer)
'
' force user to confirm delete operation
'
Dim nResult As Integer
'
nResult = MsgBox("Delete the current record?",
_vbInformation + vbYesNo, "DBGrid.BeforeDelete")
If nResult = vbNo Then
Cancel = True ' cancel delete op
End If
End Sub |
|
|
|
|
|
|
|
|
Again, no real news here. Simply ask the user to confirm the delete operation. If the answer is No, the operation is canceled. Now add the code to report the results of the delete. Put this code in the DBGrid1.AfterDelete event: |
|
|
|
|
|
|
|
|
Private Sub DBGrid1_AfterDelete()
'
' tell user the news!
'
MsgBox "Record has been deleted", vbInformation, "DBGrid.AfterDelete"
End Sub |
|
|
|
|
|